<?php

namespace app\admin\model;

use app\admin\model\User as UserModel;
use app\common\model\VipHistory as BaseModel;
class VipHistory extends BaseModel
{

    /**
     * 搜索器 用户id
     */
    public function searchUserIdAttr($query, $value){
        if ($value) {
            $query->where('user_id', $value);
        }
    }

    /**
     * 搜索器 字段phone
     */
    public function searchPhoneAttr($query, $value){
        if ($value) {
            $userIds = UserModel::where('phone','like',$value.'%')->column('id');
            $userIds = $userIds?:[0];
            $query->where('user_id','in',$userIds);
        }
    }

    /**
     * 搜索器搜索订状态
     */
    public function searchStatusAttr($query,$value)
    {
        if ($value!==''){
            $query->where('status',$value);
        }
    }

    /**
     * 搜索器 是否体验
     */
    public function searchIsTrialAttr($query, $value){
        if ($value!=''){
            $query->where('is_trial',$value);
        }
    }

    /**
     * 搜索器 查询时间范围
     */
    public function searchCreateTimeAttr($query, $value)
    {
        if ($value) {
            $query->whereTime('create_time', 'between', explode(' - ', $value));
        }
    }

}